//package org.ricks.tcp.action;
//
//import com.google.protobuf.InvalidProtocolBufferException;
//import com.lovisle.gs.server.protobuf.message.Enums;
//import com.lovisle.gs.server.protobuf.message.Info;
//import com.lovisle.gs.server.protobuf.message.MsgLogin;
//import org.ricks.boot.utils.TimeUtils;
//import org.ricks.ioc.anno.Action;
//import org.ricks.net.action.anno.ActionMethod;
//import org.ricks.net.DefaultContext;
//import org.ricks.net.DefaultPacket;
//import org.ricks.tcp.entity.DBBasePassCard;
//import org.ricks.tcp.entity.DBLevelGift;
//import org.ricks.tcp.entity.DBPassCard;
//import org.ricks.tcp.entity.DBSevenDaySign;
//import org.ricks.tcp.protobuf.*;
//
//import java.nio.ByteBuffer;
//import java.nio.ByteOrder;
//import java.util.*;
//import java.util.stream.Collectors;
//import java.util.stream.Stream;
//
//@Action
//public class LoginAction {
//
//
////    @ActionMethod(cmd = 1281)
////    public void login (DefaultContext<DefaultPacket> defaultContext) {
////        try {
////            System.err.println(new String(defaultContext.getPacket().getPacket()));
////            MsgLogin.MsgEnterGameRequest req = MsgLogin.MsgEnterGameRequest.parseFrom(defaultContext.getPacket().getPacket());
////            System.err.println("进去开始登录:" + req.getToken());
////            MsgLogin.MsgEnterGameResponse.Builder resp = MsgLogin.MsgEnterGameResponse.newBuilder();
////            Info.PlayerInfo.Builder pbplayer = Info.PlayerInfo.newBuilder();
////            pbplayer.setName("ricks-is-god");
////            pbplayer.setGender(Enums.Gender.forNumber(0));
////            pbplayer.setPlayerId(String.valueOf(1000000000));
////            pbplayer.setVip(12);
////
////            resp.setPlayer(pbplayer.build());
////            resp.setNewPlayer(false);
////            resp.setTime(TimeUtils.now());
////
////            byte[] bytes = resp.build().toByteArray();
////            ByteBuffer byteBuffer = ByteBuffer.allocate(2 + bytes.length).order(ByteOrder.BIG_ENDIAN);
////            byteBuffer.putShort((short) 1282);
////            byteBuffer.put(bytes);
////            byteBuffer.flip();
////            byte[] data = new byte[byteBuffer.remaining()];
////            byteBuffer.get(data);
////            defaultContext.getSession().send(data);
//////            defaultContext.getSession().s
//////            CoreThreadPool.getInstance().addSynTask(new LoginResult(sessionId, resp.build()));
////
////        } catch (InvalidProtocolBufferException e) {
////            throw new RuntimeException(e);
////        }
////    }
//
//    @ActionMethod(cmd = 10017)
//    public void loadLevelGiftInfo (DefaultContext<DefaultPacket> defaultContext) {
//        DBLevelGift dbLevelGift = new DBLevelGift();
//        dbLevelGift.setPlayerId(1000000000);
//        dbLevelGift.setObjectId(1);
//        dbLevelGift.setLevel(1);
//
//        byte[] bytes = buildLoadLevelGiftInfos(List.of(dbLevelGift)).toByteArray();
//
//        ByteBuffer byteBuffer = ByteBuffer.allocate(2 + bytes.length).order(ByteOrder.BIG_ENDIAN);
//        byteBuffer.putShort((short) 10018);
//        byteBuffer.put(bytes);
//        byteBuffer.flip();
//        byte[] data = new byte[byteBuffer.remaining()];
//        byteBuffer.get(data);
//        defaultContext.getSession().send(data);
//
//    }
//
//
//    /**
//     * 构建通行证所有信息结构体
//     * @param dbBasePassCard
//     * @param dbPassCards
//     */
//    private MsgPassCard.MS_LoadPassCardInfos buildLoadPassCardInfos (DBBasePassCard dbBasePassCard, Collection<DBPassCard> dbPassCards) {
//        MsgPassCard.MS_LoadPassCardInfos.Builder builder = MsgPassCard.MS_LoadPassCardInfos.newBuilder();
//        builder.setCurrPassCardLv(dbBasePassCard.getLv());
//        builder.setCurrPassCardExp(dbBasePassCard.getExp());
//        builder.setUnlockGrade2PassCard(dbBasePassCard.isGrade2Unlock());
//        builder.setUnlockGrade3PassCard(dbBasePassCard.isGrade3Unlock());
//        List<MsgPassCard.PassCardInfo> passCardInfos = dbPassCards.stream().map(this::buildPassCardInfoProto).collect(Collectors.toList());
//        builder.addAllPassCardInfos(passCardInfos);
//        return builder.build();
//    }
//
//    /**
//     * 构建通行证基础信息结构体
//     * @param dbPassCard
//     * @return
//     */
//    private MsgPassCard.PassCardInfo buildPassCardInfoProto (DBPassCard dbPassCard) {
//        MsgPassCard.PassCardInfo.Builder builder = MsgPassCard.PassCardInfo.newBuilder();
//        builder.setPassCardLv(dbPassCard.getLv());
//        builder.setFreePassCard(dbPassCard.isGrade1State());
//        builder.setGrade2PassCard(dbPassCard.isGrade2State());
//        builder.setGrade3PassCard(dbPassCard.isGrade3State());
//        return builder.build();
//    }
//
//
//    /**
//     * 构建等级礼包所有信息结构体
//     * @param dbLevelGifts
//     */
//    private MsgLevelGift.MS_LoadLevelGiftInfos buildLoadLevelGiftInfos ( Collection<DBLevelGift> dbLevelGifts) {
//        MsgLevelGift.MS_LoadLevelGiftInfos.Builder builder = MsgLevelGift.MS_LoadLevelGiftInfos.newBuilder();
//        builder.setGradeGiftUnlock(false);
//        List<MsgLevelGift.LevelGiftInfo> passCardInfos = dbLevelGifts.stream().map(this::buildLevelGiftInfoProto).collect(Collectors.toList());
//        builder.addAllLevelGiftInfos(passCardInfos);
//        return builder.build();
//    }
//
//    /**
//     * 构建等级礼包基础信息结构体
//     * @param dbLevelGift
//     * @return
//     */
//    private MsgLevelGift.LevelGiftInfo buildLevelGiftInfoProto (DBLevelGift dbLevelGift) {
//        MsgLevelGift.LevelGiftInfo.Builder builder = MsgLevelGift.LevelGiftInfo.newBuilder();
//        builder.setLevel(dbLevelGift.getLevel());
//        builder.setFreeGift(dbLevelGift.isFreeGift());
//        builder.setGradeGift(dbLevelGift.isGradeGift());
//        return builder.build();
//    }
//
//    @ActionMethod(cmd = 10005)
//    public void loadPassCardInfo (DefaultContext<DefaultPacket> defaultContext) {
//        DBBasePassCard dbBasePassCard = new DBBasePassCard();
//        dbBasePassCard.setPlayerId(1000000000);
//        dbBasePassCard.setLv(1);
//        DBPassCard dbPassCard = new DBPassCard();
//        dbPassCard.setLv(1);
//        dbPassCard.setPlayerId(1000000000);
//        dbPassCard.setObjectId(1);
//
//        byte[] bytes = buildLoadPassCardInfos(dbBasePassCard, List.of(dbPassCard)).toByteArray();
//
//        ByteBuffer byteBuffer = ByteBuffer.allocate(2 + bytes.length).order(ByteOrder.BIG_ENDIAN);
//        byteBuffer.putShort((short) 10006);
//        byteBuffer.put(bytes);
//        byteBuffer.flip();
//        byte[] data = new byte[byteBuffer.remaining()];
//        byteBuffer.get(data);
//        defaultContext.getSession().send(data);
//
//    }
//
//
//    @ActionMethod(cmd = 9991)
//    public void getSevenDayInfo (DefaultContext<DefaultPacket> defaultContext) {
//        boolean unlockSenior = false;
//        MsgActivity.MS_MsgSevenDaysSignRes.Builder builder = MsgActivity.MS_MsgSevenDaysSignRes.newBuilder();
//        builder.setUnlockSenior(unlockSenior);
//
//        DBSevenDaySign sevenDaySign = new DBSevenDaySign();
//        sevenDaySign.setDays(1);
//        sevenDaySign.setPlayerId(1000000000);
//
//        List<DBSevenDaySign> dbSevenDaySigns = new ArrayList<>();
//        for (int i = 2; i <= 7 ; i++) {
//            DBSevenDaySign sevenDaySign1 = new DBSevenDaySign();
//            sevenDaySign.setDays(i);
//            sevenDaySign.setPlayerId(1000000000);
//            dbSevenDaySigns.add(sevenDaySign1);
//        }
//        List<MsgActivity.SevenDaysSignInfo> sevenDaysSignInfos = Stream.of(sevenDaySign)
//                .map(this::buildSevenDaySignProtoBuf).collect(Collectors.toList());
//
//        List<MsgActivity.SevenDaysSignInfo> unSignInfos = dbSevenDaySigns.stream()
//                .map(x -> buildSevenDaySignProtoBuf(x.getDays())).toList();
//        sevenDaysSignInfos.addAll(unSignInfos);
//        builder.addAllSignInfo(sevenDaysSignInfos);
//
//
//        byte[] bytes = builder.build().toByteArray();
//
//        ByteBuffer byteBuffer = ByteBuffer.allocate(2 + bytes.length).order(ByteOrder.BIG_ENDIAN);
//        byteBuffer.putShort((short) 9992);
//        byteBuffer.put(bytes);
//        byteBuffer.flip();
//        byte[] data = new byte[byteBuffer.remaining()];
//        byteBuffer.get(data);
//        defaultContext.getSession().send(data);
//
//    }
//
//    /**
//     * 构建七日签到基础信息protobuf协议体
//     *
//     * @param dbSevenDaySign 七日签到db对象
//     * @return MsgActivity.SevenDaysSignInfo
//     */
//    private MsgActivity.SevenDaysSignInfo buildSevenDaySignProtoBuf(DBSevenDaySign dbSevenDaySign) {
//        MsgActivity.SevenDaysSignInfo.Builder builder = MsgActivity.SevenDaysSignInfo.newBuilder();
//        builder.setWeekDays(dbSevenDaySign.getDays());
//        builder.setSignState(true);
//        return builder.build();
//    }
//
//    private MsgActivity.SevenDaysSignInfo buildSevenDaySignProtoBuf(int weekDays) {
//        MsgActivity.SevenDaysSignInfo.Builder builder = MsgActivity.SevenDaysSignInfo.newBuilder();
//        builder.setWeekDays(weekDays);
//        builder.setSignState(false);
//        return builder.build();
//    }
//
//
//    @ActionMethod(cmd = 8737)
//    public void getAllStageProgressReward (DefaultContext<DefaultPacket> defaultContext) {
//        List<MsgStage.StageProgressRewardInfo> infos = new ArrayList<>();
//        MsgStage.StageProgressRewardInfo.Builder b = MsgStage.StageProgressRewardInfo.newBuilder();
//        b.setStageId(1);
//        b.setName("牛逼");
//        b.setLevel(1);
//        b.setHeadIcon(1);
//        b.setUsingTitleId(1);
//        b.setHasGainProgressReward(false);
//        b.setHasGainProgressReward(true);
//
//        infos.add(b.build());
//
//        MsgStage.MS_GetAllStageProgressReward.Builder send = MsgStage.MS_GetAllStageProgressReward.newBuilder();
//        send.addAllInfos(infos);
//
//        byte[] bytes =send.build().toByteArray();
//
//        ByteBuffer byteBuffer = ByteBuffer.allocate(2 + bytes.length).order(ByteOrder.BIG_ENDIAN);
//        byteBuffer.putShort((short) 8738);
//        byteBuffer.put(bytes);
//        byteBuffer.flip();
//        byte[] data = new byte[byteBuffer.remaining()];
//        byteBuffer.get(data);
//        defaultContext.getSession().send(data);
//
//    }
//
//
//    @ActionMethod(cmd = 4353)
//    public void pushAllItemMsg (DefaultContext<DefaultPacket> defaultContext) {
//        MsgItem.MsgAllItemsResponse.Builder resp = MsgItem.MsgAllItemsResponse.newBuilder();
//
//        resp.addItems(createItemInfo());
//
//        byte[] bytes = resp.build().toByteArray();
//
//        ByteBuffer byteBuffer = ByteBuffer.allocate(2 + bytes.length).order(ByteOrder.BIG_ENDIAN);
//        byteBuffer.putShort((short) 4354);
//        byteBuffer.put(bytes);
//        byteBuffer.flip();
//        byte[] data = new byte[byteBuffer.remaining()];
//        byteBuffer.get(data);
//        defaultContext.getSession().send(data);
//
//    }
//
//    public Info.ItemInfo createItemInfo() {
//        Info.ItemInfo.Builder ii = Info.ItemInfo.newBuilder();
//        ii.setItemId(1001);
//        ii.setItemOid(1001);
//        ii.setNum(1000);
//        ii.setVisible(true);
//        ii.setLevel(0);
//        ii.setGemID(0);
//        ii.setGemPos(0);
//        return ii.build();
//    }
//
//
//
////    @ActionMethod(cmd = 17409)
////    public void getTaskInfo (DefaultContext<DefaultPacket> defaultContext) {
////        MS_AllTask.Builder resp = MS_AllTask.newBuilder();
////        resp.addAllTaskInfo(this.createAllTaskInfo(pid));
////
////        this.sendMessage(pid, new GetTaskResult(resp.build()));
////
////        byte[] bytes = buildLoadLevelGiftInfos(List.of(dbLevelGift)).toByteArray();
////
////        ByteBuffer byteBuffer = ByteBuffer.allocate(2 + bytes.length).order(ByteOrder.BIG_ENDIAN);
////        byteBuffer.putShort((short) 10018);
////        byteBuffer.put(bytes);
////        byteBuffer.flip();
////        byte[] data = new byte[byteBuffer.remaining()];
////        byteBuffer.get(data);
////        defaultContext.getSession().send(data);
////
////    }
//
//}
